import { createI18n } from 'vue-i18n'
import zh from '@/locals/zh.json'
import en from '@/locals/en.json'
// import { getItem, setItem } from '@/utils/localStorage'

const messages = {
  en,
  zh
}
const language = (navigator.language || 'en').toLocaleLowerCase() // 这是获取浏览器的语言
const storeLang = language.split('-')[0]
const historyLocal = window.localStorage.getItem('lang')
if (!historyLocal) {
  window.localStorage.setItem('_lang', storeLang)
}
const i18n = createI18n({
  locale: window.localStorage.getItem('_lang') || storeLang || 'en', // 首先从缓存里拿，没有的话就用浏览器语言，
  fallbackLocale: 'en', // 设置备用语言
  legacy: false,
  messages
})

export default i18n
